﻿function EventCalendar (array, container)
{
	this.dom = array;
	this.set = function (name, value) { this.dom[name]=value; }
	this.get = function (name)
	{
		try { return this.dom[name];
		} catch (ex) { return ''; }
		return false;
	}
	this.id = this.get('id'); 
	this.calendar_name = this.get('calendar_name'); 
	this.calendar_type = this.get('calendar_type'); 
	this.maxevents = this.get('maxevents'); 
	this.truncate = this.get('truncate'); 
	this.fontsize = this.get('fontsize'); 
	this.show_ads = this.get('show_ads'); 
	this.calendar_loc = this.get('calendar_loc'); 
	this.calendar_view = parseInt(this.get('calendar_view')); 
	this.date   = new Date ();
	this.day    = [];
	this.week   = [];
	this.month  = [];
	this.events = [];
	this.container = container;
	this.element = null;
	this.firstdayoftheweek = null;
	this.lastdayoftheweek = null;
	
	this.Serialize = function ()
	{
        var htm='';
	    htm+='<calendar>\n'; 
        htm+='  <r>\n';
        for (var i in this.dom)
        {
            htm+='   <f n="'+i+'"><![CDATA[' + this.dom[i] + ']]></f>\n'; 
        }
        htm+='  </r>\n';   
	    htm+='</calendar>\n'; 
	    return htm;  
	}
	
	this.save = function ()
	{ 
	    wsdl(DATA_URL, EventCalendar.OnSave, "Receiving save response...", this.Serialize()) ;      
	}
	
	this.find = function (id)
	{
		for (var i in this.events)
		{
			if (this.events[i]['ID']==id) return this.events[i];
		}
		return false;
	}
	
	this.write = function (htm,block)
	{
        if (this.container)
        {
            this.element=document.getElementById (this.container);
			if (!this.element) this.element = this.addcontainer();
            if (this.element) 
            {
				if (block) htm='<table width="100%" height="100%"><tr><td align=center>'+htm+'</td></tr></table>';
                this.element.innerHTML = htm;
                return true;
            } 
        }
		confirm ("Unable to write data because the container could not be found or created");
        return false;
	} 
	
	this.addcontainer = function ()  
	{
		var div = document.createElement('div');
		div.id = this.container;
		div.innerHTML = 'Downloading ' + this.calendar_name;
		document.body.appendChild(div);
		return div;
	} 
	
	this.parseweek = function ()
	{
	    this.add=function(d,e)
		{ if (this.week[d]['w'+e.ID]) return false; 
		  if (this.week[d].length>this.maxevents) return false;  
		  this.week[d].push (e); this.week[d]['w'+e.ID]=e; };
	    this.firstdayoftheweek = new Date (this.date.getFullYear(), this.date.getMonth(), this.date.getDate() - this.date.getDay());
        this.lastdayoftheweek  = new Date (this.firstdayoftheweek.getFullYear(), this.firstdayoftheweek.getMonth(), this.firstdayoftheweek.getDate() + 6);
	    this.week = [];
	    for (var d=0;d<7;d++) this.week[d]=[];
        for (var x in this.events)
        { 
			if (this.events[x]['CustomDate'])
				this.add ( jdate('w',this.events[x]['CustomDate']), this.events[x] );
			else if (this.events[x]['EventDate'])
				this.add ( jdate('w',this.events[x]['EventDate']), this.events[x] ); 
        }
	}
	
	this.parsemonth = function ()
	{
	    this.add=function(d,e)
		{ if (this.month[d]['m'+e.ID]) return false; 
		  if (this.month[d].length>this.maxevents) return false;  
		  this.month[d].push (e); this.month[d]['m'+e.ID]=e; };
        this.firstdayofthemonth = new Date (this.date.getFullYear(), this.date.getMonth(), 1);
        this.lastdayofthemonth  = new Date (this.firstdayofthemonth.getFullYear(), this.firstdayofthemonth.getMonth() + 1, 0);
	    this.month = [];
	    for (var d=this.firstdayofthemonth.getDate();d<this.lastdayofthemonth.getDate() + 1;d++) this.month[d]=[];
        for (var x in this.events)
        {
			if (this.events[x]['CustomDate'])
				this.add ( jdate('j',this.events[x]['CustomDate']), this.events[x] );
			else if (this.events[x]['EventDate'])
				this.add ( jdate('j',this.events[x]['EventDate']), this.events[x] );
        }
	}
	
	this.monthview = function ()
	{
	    this.parsemonth();
        var id = new Calendar(this.date.getFullYear(), this.date.getMonth() + 1, this.date.getDate(), null, null, this );//   
        id.PanelSize = "140"; 
        id.TableSize = "980"; 
        
	    id.setdate = function (num)
	    {
    	    this.Day = num; 
		    window.eventcalendar.date = this.getvalue(); 
		    window.eventcalendar.invoke();
	    } 
        id.fwd = function ()
        {
	        window.eventcalendar.date = new Date(this.Year, this.Month + 1, 1); 
		    window.eventcalendar.invoke();
        }     	
        id.back = function ()
        {
	        window.eventcalendar.date = new Date(this.Year, this.Month - 1, 1);  
		    window.eventcalendar.invoke();
        } 
        id.create();
	    var htm=id.HTML;
        return htm;
	}
	
	this.weekadd = function (date, index)
	{
	    return new Date (date.getFullYear(), date.getMonth(), date.getDate() + index);
	}
	
	this.style={
		dayname:'font-family:Georgia;font-size:14px;',
		eventname:'font-family:Georgia;font-size:11px;color:#003399;',
		roomname:'font-family:Calibri,Tahoma;font-size:10pt;',
		time:'font-family:Calibri,Tahoma;font-size:9pt;color:#3a3a3a;background-color:#FFFFCC;' ,
		daterange:'font-family:Calibri,Tahoma;font-size:9pt;color:royalblue;'
	}
	
	this.weekview = function ()
	{
	    this.parseweek();
	    var htm='';
	    var prevweek = jdate ('M j, Y', this.weekadd(this.firstdayoftheweek, -1)); 
	    var fwdweek  = jdate ('M j, Y', this.weekadd(this.lastdayoftheweek, 1)); 
	    var lastweek = jdate ('M j, Y', this.weekadd(this.date, -7)); 
	    var nextweek = jdate ('M j, Y', this.weekadd(this.date, 7)); 
        htm += '<table cellspacing="0" cellpadding="2" height="100%" width="100%">';
        htm += '<tr>';
        htm += '<td colspan="1" height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=left>';
        htm += ' <a href="javascript:window.eventcalendar.redate (\'' + lastweek + '\')">&#171; ' + prevweek + '</a>';
        htm += '</td>';
        htm += '<td colspan="5" height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=center>';
        htm += ' ' + jdate ( 'M j, Y', this.firstdayoftheweek ) + ' - ' + jdate ( 'M j, Y', this.lastdayoftheweek ) + ' ';
        htm += '</td>';
        htm += '<td colspan="1" height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=right>';
        htm += ' <a href="javascript:window.eventcalendar.redate (\'' + nextweek + '\')">' + fwdweek + ' &#187;</a>';
        htm += '</td>';
        htm += '</tr>';
        htm += '<tr>';
        for (var w=0;w<this.week.length;w++)
        {
            htm += '<td width="14%" height="24" bgcolor="#eeeee"';
			htm += ' style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;border-right:solid 1px #cccccc;border-left:solid 1px #fff;color:gray"';
			htm += ' align=center>';
            htm += Calendar.DayNames[w];
            htm += '</td>';
        }
        htm += '</tr>';
        htm += '<tr>';
        for (var w=0;w<this.week.length;w++)
        {
            htm += '<td class=small valign=top style="border-right:solid 1px #cccccc;border-left:solid 1px #fff">';
            for (var x=0;x<this.week[w].length;x++)
			{
				if (this.week[w][x]['EventName'])
					htm += this.weekmask (this.week[w][x]);
            }
            htm += '</td>';
        }
        htm += '</tr></table>';
        return htm;
	}
	
	this.weekmask = function (row)
	{
	    var htm='';
		htm += '<div style="background-color:#f0f0f0;padding:2px;margin:1px;border:solid 1px #999">'; 
		htm += '<a style="'+this.style.eventname+'" href="javascript:void(0)" onclick="window.eventcalendar.detail('+row['ID']+')" class="small">'; 
		htm += '' + row['EventName'] + ''; 
		htm += '</a>';  
		htm += '<div style="'+this.style.roomname+'">';
		htm += '' + row['RoomName'] + '</div><div style="'+this.style.time+'">';
		htm += jdate ('h:i a', row['EventStartTime'] ) + '-' + jdate ('h:i a', row['EventEndTime'] );
		htm += '</div></div>';
        return htm;
	}
	
	this.miniview = function ()
	{
	    var i=0,htm='';
	    var nextweek = jdate ('M j, Y', this.weekadd(this.date, 1));// dateUS ( dateSQL( this.weekadd(this.date, 7) ) );
	    var lastweek = jdate ('M j, Y', this.weekadd(this.date, -1));// dateUS ( dateSQL( this.weekadd(this.date, -7) ) );
        htm += '<table cellspacing="0" cellpadding="2" width="200">';
        htm += '<tr><td colspan="2">';
        htm += '<table cellspacing="0" cellpadding="2" width="200">';
        htm += '<tr>';
        htm += '<td height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=left>';
        htm += ' <a href="javascript:window.eventcalendar.redate (\'' + lastweek + '\')">&#171; ' + jdate('M j', lastweek) + '</a>';
        htm += '</td>';
        htm += '<td  height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=center>';
        htm += ' ' + jdate ( 'M j', this.date ) + ' ';
        htm += '</td>';
        htm += '<td height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=right>';
        htm += ' <a href="javascript:window.eventcalendar.redate (\'' + nextweek + '\')">' + jdate('M j', nextweek) + ' &#187;</a>';
        htm += '</td>';
        htm += '</tr>';
        htm += '</table>';
        htm += '</td></tr>';
        htm += '<tr><td colspan="2" width="200">';
        for (var x in this.events)
        {
            htm += this.weekmask ( this.events[x] );
			i++;
			if (i>this.maxevents) break;
        }
        htm += '</td></tr>';
        htm += '</table>';
        return htm;
	}
	
	this.dayview = function ()
	{
	    var htm='';
	    var nextweek = jdate ('M j, Y', this.weekadd(this.date, 1));// dateUS ( dateSQL( this.weekadd(this.date, 7) ) );
	    var lastweek = jdate ('M j, Y', this.weekadd(this.date, -1));// dateUS ( dateSQL( this.weekadd(this.date, -7) ) );
        htm += '<table cellspacing="0" cellpadding="2">';
        htm += '<tr><td colspan="2">';
        htm += '<table cellspacing="0" cellpadding="2" width="100%">';
        htm += '<tr>';
        htm += '<td height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=left>';
        htm += ' <a href="javascript:window.eventcalendar.redate (\'' + lastweek + '\')">&#171; ' + lastweek + '</a>';
        htm += '</td>';
        htm += '<td  height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=center>';
        htm += ' ' + jdate ( 'M j, Y', this.date ) + ' ';
        htm += '</td>';
        htm += '<td height="24" bgcolor="#eeeee" style="'+this.style.dayname+'border-bottom:solid 1px #cccccc;color:gray" align=right>';
        htm += ' <a href="javascript:window.eventcalendar.redate (\'' + nextweek + '\')">' + nextweek + ' &#187;</a>';
        htm += '</td>';
        htm += '</tr>';
        htm += '</table>';
        htm += '</td></tr>';
        for (var x in this.events)
        {
            htm += this.daymask ( this.events[x] );
        }
        htm += '</table>';
        return htm;
	}
	
	this.daymask = function (row)
	{
	    var htm='',f=function(r) 
		{ if (r['RecurseType']&&r['RecurseType']>=0) 
		  return Calendar.scope(r.EventDate, r.RecurseEndDate, 
		  r.RecurseType, r.RecurseUnit); return ''; };
        htm += '<tr>';
        htm += ' <td class="datarow" nowrap="nowrap" style="'+this.style.time+'border-right:solid 1px #cccccc;border-bottom:solid 1px #cccccc" bgcolor="#f0f0f0" align="right" width="50">';
        htm +=    jdate ('h:ia', row['EventStartTime']) + '<br>';
        htm +=    jdate ('h:ia', row['EventEndTime']);
        htm += ' </td>';
        htm += ' <td class="datarow" style="'+this.style.eventname+'border-left:solid 1px #fff;border-bottom:solid 1px #cccccc" bgcolor="#f0f0f0" width="100%">';
        htm += '<a href="javascript:void(0)" onclick="window.eventcalendar.detail('+row['ID']+')">'; 
        htm += '' + row['EventName'] + '';
        htm += '</a>';
        htm += ' in ';
        htm += ' <span style="'+this.style.roomname+'">' + row['RoomName'] + '</span>'; 
        htm += ' <div style="'+this.style.daterange+'">' + f(row) + '</div>'; 
        htm += ' </td>';
        htm += '</tr>';
        return htm;
	}
	
	this.detail = function (id)
	{
		this.eventid = id;
    	var url = DATA_URL+'action/roomlist/id/' + this.eventid;  ;
    	wsdl (url, function () { window.eventcalendar.ondetail(); }, 'loading event rooms...');  
	} 
	
	this.getdates = function ()
	{
		var url = DATA_URL+'action/range/id/' + this.eventid;    
		wsdl (url, function () { window.eventcalendar.ondatesloaded(); }, 'loading event dates...');  
	}
	
	this.ondetail = function (text, remote)
	{
		if (remote || window.http.readyState==ReadyState.DONE)   
		{  
			var data = remote ? text : window.http.responseText;
			if (window.dom.loadXML (data))  
			{  
				var si=new SimpleXMLIterator (window.dom);   
				this.Rooms = [];  
				while (!si.eof)  
				{     
					this.Rooms.push (si.data['roomname']);  
					si.movenext ();  
				}   
			}   
			Controller.Clear();   
			this.getdates ();
//			var url = DATA_URL+'action/range/id/' + this.eventid;    
//			wsdl (url, function () { window.eventcalendar.ondatesloaded(); }, 'loading event dates...');   
		}    
	}
	
	
	this.ondatesloaded = function (text, remote)
	{     
		var dom=this.find (this.eventid);
		var dates=[]; dates.push( '<b style="color:blue;'+this.style.dayname+'">' + jdate('M j, Y', dom['EventDate']) + '</b>' );
		if (remote || window.http.readyState==ReadyState.DONE)  
		{ 
			var data = remote ? text : window.http.responseText;
			if (window.dom.loadXML (data))  
			{ 
				var si=new SimpleXMLIterator (window.dom);     
				while (!si.eof)  
				{    
					dates.push( '<span style="'+this.style.dayname+'">' + si.data['FriendlyDate'] + '</span>' );  
					si.movenext ();  
				}   
			}   
			Controller.Clear();   
			var htm='';
			htm +='<div style="padding:10pt">';
			htm +='<a style="'+this.style.dayname+'" href="javascript:void(0)" onclick="window.eventcalendar.rendercalender()">';
			htm +='&#171; Back to ' + this.calendar_name + '</a><hr noshade size=1 color="#666"/>';
			htm +='<h2>' + dom['EventName'] + '<br><small style="'+this.style.roomname+'"> in ' + this.Rooms.join (', ') + '</small></h2>'; 
			htm += 'Occurs on: ' +  dates.join (' and ');
			htm +='</div>';
			
			this.write (htm); 
		}       
		
	}
	
	
	this.review = function (x)
	{
		this.calendar_view=x;
		this.invoke();
	}
	
	
	this.rendercalender = function ()
	{
        var data='',db='';
		switch (this.calendar_view)
		{
			case (EventCalendar.WEEK):
				data = this.weekview ();
				break;
			case (EventCalendar.MONTH):
				data = this.monthview ();
				break;
			case (EventCalendar.MINI):
				data = this.miniview ();
				break;
			default:
				data = this.dayview (); 
		} 
		this.timestamp.rendered=new Date();
		this.querystring();
		var vue = ['LIST','WEEK','MONTH','MINI'];
		var url = (DATA_URL.indexOf(':')<0?(location.protocol + '//' + location.host):'') + DATA_URL + "calendars/" + this.id ;
		var htm = '';// + this.response;
		//for (var x in this.timestamp) htm += '<small style=color:#999>' + x + ': ' + jdate('i:s u', this.timestamp[x]) + '</small> | ';
		htm += '<div style="'+this.style.eventname+'">&nbsp;';
		if (this.calendar_view==EventCalendar.MINI)
		{
		}
		else
		{
			htm += 'Embed: <input class=flat size=30 ';
			htm += ' value="&lt;script language=\'javascript\' src=\'' + url + '\'&gt;&lt;/script&gt;"';
			htm += '>&nbsp;';
			htm += 'Widget: <input class=flat size=30 ';
			htm += ' value="&lt;script language=\'javascript\' src=\'' + url + '/view/mini\'&gt;&lt;/script&gt;"';
			htm += '>&nbsp;';
		}
		//htm += '<div style="background-color:#FFFFCC;font:9pt georgia">' + this.querystring() + '</div>';
//		htm += '<br>' + this.events.length;
		for (var m=0;m<vue.length;m++)
		{
			if (this.calendar_view==EventCalendar[vue[m]]) htm += vue[m] + ' | ';
			else htm += '<a href="javascript:void(0)" onclick="window.eventcalendar.review('+EventCalendar[vue[m]]+')">'+vue[m]+'</a>' + ' | ';
		}
		if (this.calendar_view==EventCalendar.MINI) htm+=data;
		else if (this.events.length>0)
		{
			htm += '<div id="dcpre" style="border:solid 1px;border-color:#666;background-color:#ffffff;overflow:auto;margin:1px;padding:2px">';
			htm += data; 
			htm += '</div>';
		}
		else htm += data + '<div style="' + this.style.eventname + '">No events scheduled</div>';
		
		
		if (this.write (htm))
		{
			AttachResizer ('dcpre', 10, 40); 
			if (EventCalendar.MONTH==this.calendar_view)
			{
				var dx=document.getElementsByTagName ('TABLE');
				for (var m=0;m<dx.length;m++)
				{  
					if (dx[m].className=='CalendarTable')
					{
						dx[m].invoke = function () 
						{ 
							var b = window_w()-20;
							this.style.width = b + 'px';  
							document.title = this.style.width;
						}
						
						window.resizer.subscribe (dx[m]);
						dx[m].invoke ();
					}
				}
				
				for (var m=0;m<7;m++)
				{ 
					var dm=document.getElementById ('wm'+m+'');
					if (dm)
					{
						dm.invoke = function () 
						{
							var b = (window_w()-60) / 7;
							this.style.width = b + 'px';  
						}
						
						window.resizer.subscribe (dm);
						dm.invoke ();
					}
				}
				
				var dx=document.getElementsByTagName ('TD');
				for (var m=0;m<dx.length;m++)
				{  
					if (dx[m].className=='WeekDay'||dx[m].className=='WeekEnd')
					{
						dx[m].invoke = function () 
						{ 
							var b = (window_w()-20) / 7;
							this.style.width = b;  
							this.width = b;   
						}
						
						window.resizer.subscribe (dx[m]);
						dx[m].invoke ();
					}
				}
			}
		}
	}
	
	this.timestamp = {
		created 	: new Date(),
		sent    	: null,
		received 	: null,
		processed 	: null,
		rendered 	: null
	};
	
	this.invoke = function ()
	{
	    this.write ('&nbsp;Loading events for ' + this.calendar_name + '...');
		this.ajaxid=Math.floor(Math.random() * 1000);
		var url  = this.querystring(); 
		this.timestamp.sent = new Date();
		var ajax = new ajaxObject(url, function(text, id) { window.eventcalendar.draw (text, id) }) ;
		ajax.update (this.ajaxid);
       // wsdl (url, function() { window.eventcalendar.draw () });  
	}
	
	this.response = '';
	this.draw = function (text, id, remote)
	{  
		this.timestamp.received = new Date();
		this.debugtext = '';
		if (this.ajaxid)
		{
			if (this.ajaxid!=id) return false;
		}
        
		if (remote || window.http.readyState==ReadyState.DONE)   
        {  
            if (window.dom.loadXML (text))  
            {    
				this.response = '[<textarea>'+text+'</textarea>]';
                var si=new SimpleXMLIterator (window.dom, 'r', 'n');  
                this.events = [];
                while (!si.eof)  
                {     
					if (si.data&&si.data['EventName'])
                        this.events.push (si.data);  
                    si.movenext ();  
                }
                var mk=window.dom.getElementsByTagName ('marker'); 
                for (var m=0;m<mk.length;m++)
                {
                    this.debugtext += mk[m].getAttribute ('name')+':'+mk[m].getAttribute ('value')+'<br>';
                }   
            }  else confirm ("Could not open calendar xml!");  
            Controller.Clear();    
			
			 
			
			this.timestamp.processed = new Date();
            this.rendercalender ();
        }   
        else
        {
            var htm='&nbsp;Loading events for ' + this.calendar_name + '...'
            switch (window.http.readyState)
            {
                case ReadyState.SENDING:
                    htm += '<span style="background-color:#FFFFCC;padding:2px;font-weight:bold">Contacting server...</span>';
                    break;
                case ReadyState.LOADING:
                    htm += '<span style="background-color:#FFFFCC;padding:2px;font-weight:bold">Message received...</span>';
                    break;
                case ReadyState.PROCESSING:
                    htm += '<span style="background-color:#FFFFCC;padding:2px;font-weight:bold">' + window.processmessage + '</span>';
                    break;
            }
            this.write (htm);
        }   
      if (this.debug) DebugToolBar.invoke ();
	  else document.title = APPLICATION_NAME + ' - ' + this.calendar_name;
	}
	
	this.redate = function (x)
	{    
	    this.date = new Date(x);
		this.invoke();
	}
	
	this.retype = function (x)
	{    
	    this.calendar_view = parseInt(x);
	    this.dom['calendar_view'] = this.calendar_view;
	    this.invoke();
	}
	
	this.querystring = function ()
	{  
	    var marker  = new Date(this.date);
	    var request = '/start/' + jdate ('Y-m-d', marker ) ;
	    switch (this.calendar_view)
	    {
	        case (EventCalendar.WEEK):
	            var firstdayoftheweek = new Date (marker.getFullYear(), marker.getMonth(), marker.getDate() - marker.getDay());
	            var lastdayoftheweek  = new Date (firstdayoftheweek.getFullYear(), firstdayoftheweek.getMonth(), firstdayoftheweek.getDate() + 6);
	            request = '/start/' + jdate ('Y-m-d', firstdayoftheweek ) + '/end/' + jdate ('Y-m-d', lastdayoftheweek ) ;
	            break;
	        case (EventCalendar.MONTH):
	            var firstdayofthemonth = new Date (marker.getFullYear(), marker.getMonth(), 1);
	            var lastdayofthemonth = new Date (firstdayofthemonth.getFullYear(), firstdayofthemonth.getMonth() + 1, 0);
	            request = '/start/' + jdate ('Y-m-d', firstdayofthemonth ) + '/end/' + jdate ('Y-m-d', lastdayofthemonth ) ;
	            break;
	    } 
        this.widget  = DATA_URL + "calendars/" + this.id ;
        this.address = this.widget + '/date/' + jdate ('Y-m-d', this.date);
        this.remote  = this.widget + request;
        this.url     = DATA_URL + "action/sql_calendar" + request + "/id/" + this.id + "/op/xms";   
        return this.url;
	}
    window.eventcalendar = this;
	this.debug=false;
} 

EventCalendar.OnSave = function ()
{
    if (window.http.readyState==ReadyState.DONE)
    {
        Controller.Clear();    
       // alert (window.http.responseText)
        Controller.SelectedCalendar = -1;
        
	    var re = /\{(\d+)\}/ ;
	    var mm = re.exec (window.http.responseText);
	    if (mm) Controller.SelectedCalendar = parseInt(mm[1]);
	    
	    LoadGlobalCalendarList (function() { Controller.Reload(); })  ;
//        wsdl (DATA_URL+'action/dump/op/xms/id/ebp_event_calendars', EventCalendar.OnReload, "Loading list...");
    }
} 



EventCalendar.empty = function (name)
{ 
    return { "id" : 0,
             "calendar_name" : name,
             "calendar_type" : 0,
             "maxevents" : 10,
             "truncate" : 50,
             "fontsize" : "10pt",
             "show_ads" : "1",
             "calendar_loc" : 0,
             "calendar_view" : 0 
             };
}

// GlobalCalendarList.Build() 
EventCalendar.OnReload = function ()  
{      
	ProcessGlobalCalendarListEx (function() { Controller.Reload(); });
}  

EventCalendar.Views = ['List View','Expanded View','Week View','Simple View','Debug View','Month View','Widget View'];


EventCalendar.LIST = 0;
EventCalendar.EXPANDED = 1;
EventCalendar.WEEK = 2;
EventCalendar.SIMPLE = 3;
EventCalendar.DEBUG = 4;
EventCalendar.MONTH = 5;
EventCalendar.MINI = 6;

//var lastdayofthemonth = new Date (2008,2,0);
//alert (lastdayofthemonth);